package com.mx102.kosmos;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL11;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g3d.loaders.obj.ObjLoader;

public class Statek {
	
	private float angleSpeed=50;
	private float positionSpeed=70;
	
	private Mesh statek;
	private Texture texture;
	private float position;
	private float angle;
	private float positionDelta;
	private float angleDelta;	

	
	
	
	public Statek() {
		statek = ObjLoader.loadObj(Gdx.files.internal("ship.obj").read(),true);
		statek.scale(3, 3, 3);
		texture = new Texture(Gdx.files.internal("ship.png"), true);
		texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
		
	}
	
	public void moveLeft() {
		angleDelta=angleSpeed;
		positionDelta=-positionSpeed;
		
	}
	
	public void moveRight() {
		angleDelta=-angleSpeed;
		positionDelta=positionSpeed;
	}
	
	public void stop() {
		angleDelta=0;
		//angle=0;
		positionDelta=0;
		
	}
	
	public float getPosition() {
		return position;
	}

	
	public void render(GL11 gl,float delta) {
		
		if(Math.abs(angle)<45) angle+=angleDelta*delta;
		if((angleDelta==0)&&(angle>0)) angle-=2*angleSpeed*delta;
		if((angleDelta==0)&&(angle<0)) angle+=2*angleSpeed*delta;
		
		position+=positionDelta*delta;
		
		
		
		gl.glPushMatrix();
		gl.glTranslatef(position,0,0);
		gl.glRotatef(angle, 0, 0, 1);
		texture.bind();
		statek.render(GL11.GL_TRIANGLES);
		gl.glPopMatrix();
	
		

		
	
	}
	
	
	
}
